﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using MyVoteMVC.Domain;
using System.Data.Entity.Infrastructure;
using MyVoteMVC.Data.Mapping;

namespace MyVoteMVC.Data
{
    public class VoteDBContext : DbContext
    {
        public VoteDBContext()
            : base("VoteDBContext")
        {
            if (!Database.Exists("VoteDBContext"))
            {
                Database.SetInitializer<VoteDBContext>(new VoteDbInitializer());
            }
            else
            {
                Database.SetInitializer<VoteDBContext>(null);
            }
            //else
            //{
            //    Database.SetInitializer<VoteDBContext>(new VoteDbInitializerIfModelChanges());
            //    Database.Initialize(false);
            //}
            
        }

        public IDbSet<VT_Activities> Activities { get; set; }
        public IDbSet<VT_ActivityImage> ActivityImages { get; set; }
        public IDbSet<VT_Items> Items { get; set; }
        public IDbSet<VT_ItemImage> ItemImages { get; set; }
        public IDbSet<VT_Messages> Messages { get; set; }
        public IDbSet<VT_Questions> Questions { get; set; }
        public IDbSet<VT_Tickets> Tickets { get; set; }
        public IDbSet<VT_Users> Users { get; set; }
        public IDbSet<VT_Projects> Projects { get; set; }
        public IDbSet<VT_ProjectImage> ProjectImages { get; set; }
        public IDbSet<VT_Dictionaries> Dictionaries { get; set; }
        public IDbSet<VT_Lotteries> Lotteries { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();

            modelBuilder.Configurations.Add(new VT_ActivitiesMap());
            modelBuilder.Configurations.Add(new VT_ActivityImageMap());
            modelBuilder.Configurations.Add(new VT_ItemsMap());
            modelBuilder.Configurations.Add(new VT_ItemImageMap());
            modelBuilder.Configurations.Add(new VT_MessagesMap());
            modelBuilder.Configurations.Add(new VT_QuestionsMap());
            modelBuilder.Configurations.Add(new VT_TicketsMap());
            modelBuilder.Configurations.Add(new VT_UsersMap());
            modelBuilder.Configurations.Add(new VT_ProjectImageMap());
            modelBuilder.Configurations.Add(new VT_ProjectsMap());
            modelBuilder.Configurations.Add(new VT_DictionariesMap());
            modelBuilder.Configurations.Add(new VT_LotteriesMap());
        }
    }
}
